using Catalog.Application.Brands.Interfaces;
using Catalog.Application.Brands.Queries;
using Catalog.Application.Contracts.DTOs;
using MediatR;

namespace Catalog.Application.Brands.QueryHandlers;

public class SearchBrandQueryHandler : IRequestHandler<SearchBrandQuery, List<BrandProfileDto>>
{
    private readonly IBrandReadService _brandReadService;
    public SearchBrandQueryHandler(IBrandReadService brandReadService)
    {
        _brandReadService = brandReadService;
    }
    public async Task<List<BrandProfileDto>> Handle(SearchBrandQuery request, CancellationToken cancellationToken)
    {
        var brands = await _brandReadService.GetListAsync(request.NameFilter, cancellationToken);
        return brands.Select(brand => new BrandProfileDto
        {
            Id = brand.Id,
            Name = brand.Name,
            Description = brand.Description
        })
         .ToList();
    }
}